package com.yunchang.springboot.scheduled.amazon.mws.report.datadispose;

import com.yunchang.springboot.models.mwsreportbean.MwsManageFbaInventory;
import com.yunchang.springboot.models.mwsreportbean.MwsManageFbaInventoryDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.parent.ReportDataDisposeParent;
import com.yunchang.springboot.scheduled.amazon.mws.report.datadispose.reportinterface.IReportDataDispose;
import com.yunchang.springboot.utils.DateUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author czw
 * @date 2020/7/28 0028  18:50
 * @description:
 */
@Component
public class ManageFbaInventoryDataDispose extends ReportDataDisposeParent implements IReportDataDispose {
    /**
     * 管理亚马逊库存  将获取到的数据转为实体对象数组
     *
     * @param lists
     * @param shopBrandName
     * @param area
     * @return
     */
    @Override
    public List<Object> reportDataDispose(List<List<String>> lists, String shopBrandName, String area,String sellerId) {
        List<String> titleList = lists.get(0);
        Map<String, Object> titleMap = new HashMap<>(titleList.size());
        for (int i = 0; i < titleList.size(); i++) {
            titleMap.put(titleList.get(i), i);
        }
        int skuIndex = Integer.valueOf(titleMap.get("sku").toString());
        int fnskuIndex = Integer.parseInt(titleMap.get("fnsku").toString());
        int asinIndex = Integer.valueOf(titleMap.get("asin").toString());
        int productNameIndex = Integer.valueOf(titleMap.get("product-name").toString());
        int conditionNameIndex = Integer.valueOf(titleMap.get("condition").toString());
        int yourPriceIndex = Integer.valueOf(titleMap.get("your-price").toString());
        int mfnListingExistsIndex = Integer.valueOf(titleMap.get("mfn-listing-exists").toString());
        int mfnFulfillableQuantityIndex = Integer.valueOf(titleMap.get("mfn-fulfillable-quantity").toString());
        int afnListingExistsIndex = Integer.valueOf(titleMap.get("afn-listing-exists").toString());
        int afnWarehouseQuantityIndex = Integer.valueOf(titleMap.get("afn-warehouse-quantity").toString());
        int afnFulfillableQuantityIndex = Integer.valueOf(titleMap.get("afn-fulfillable-quantity").toString());
        int afnUnsellableQuantityIndex = Integer.valueOf(titleMap.get("afn-unsellable-quantity").toString());
        int afnReservedQuantityIndex = Integer.valueOf(titleMap.get("afn-reserved-quantity").toString());
        int afnTotalQuantityIndex = Integer.valueOf(titleMap.get("afn-total-quantity").toString());
        int perUnitVolumeIndex = Integer.valueOf(titleMap.get("per-unit-volume").toString());
        int afnInboundWorkingQuantityIndex = Integer.valueOf(titleMap.get("afn-inbound-working-quantity").toString());
        int afnInboundShippedQuantityIndex = Integer.valueOf(titleMap.get("afn-inbound-shipped-quantity").toString());
        int afnInboundReceivingQuantityIndex = Integer.valueOf(titleMap.get("afn-inbound-receiving-quantity").toString());
        List<Object> insertList = new ArrayList<>(lists.size());
        for (int i = 1; i < lists.size(); i++) {
            MwsManageFbaInventoryDO mwsManageFbaInventory = new MwsManageFbaInventoryDO();
            List<String> stringList = lists.get(i);
            mwsManageFbaInventory.setShop(shopBrandName);
            mwsManageFbaInventory.setArea(area);
            mwsManageFbaInventory.setSku(stringList.get(skuIndex));
            mwsManageFbaInventory.setFnsku(stringList.get(fnskuIndex));
            mwsManageFbaInventory.setAsin(stringList.get(asinIndex));
            mwsManageFbaInventory.setProductName(stringList.get(productNameIndex));
            mwsManageFbaInventory.setGoodsCondition(stringList.get(conditionNameIndex));
            mwsManageFbaInventory.setYourPrice(stringList.get(yourPriceIndex));
            mwsManageFbaInventory.setMfnListingExists(stringList.get(mfnListingExistsIndex));
            mwsManageFbaInventory.setMfnFulfillableQuantity(stringList.get(mfnFulfillableQuantityIndex));
            mwsManageFbaInventory.setAfnListingExists(stringList.get(afnListingExistsIndex));
            mwsManageFbaInventory.setAfnWarehouseQuantity(stringList.get(afnWarehouseQuantityIndex));
            mwsManageFbaInventory.setAfnFulfillableQuantity(stringList.get(afnFulfillableQuantityIndex));
            mwsManageFbaInventory.setAfnUnsellableQuantity(stringList.get(afnUnsellableQuantityIndex));
            mwsManageFbaInventory.setAfnReservedQuantity(stringList.get(afnReservedQuantityIndex));
            mwsManageFbaInventory.setAfnTotalQuantity(stringList.get(afnTotalQuantityIndex));
            mwsManageFbaInventory.setPerUnitVolume(stringList.get(perUnitVolumeIndex));
            mwsManageFbaInventory.setAfnInboundWorkingQuantity(stringList.get(afnInboundWorkingQuantityIndex));
            mwsManageFbaInventory.setAfnInboundShippedQuantity(stringList.get(afnInboundShippedQuantityIndex));
            mwsManageFbaInventory.setAfnInboundReceivingQuantity(stringList.get(afnInboundReceivingQuantityIndex));
            mwsManageFbaInventory.setCreateTime(DateUtil.getDate());
            mwsManageFbaInventory.setSellerId(sellerId);
            mwsManageFbaInventory.setCreateTime(DateUtil.getDate());
            mwsManageFbaInventory.setFinanceStatus(1);
            insertList.add(mwsManageFbaInventory);
        }
        return insertList;
    }
}
